package com.qhhc.service.impl;

import com.qhhc.entity.CarDealer;
import com.qhhc.mapper.CarDealerMapper;
import com.qhhc.service.ICarDealerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CarDealerServiceImpl implements ICarDealerService {

    @Autowired
    private CarDealerMapper carDealerMapper;

    @Override
    public List<CarDealer> getAllDealers() {
        return carDealerMapper.selectAllDealers();
    }

    @Override
    public CarDealer getDealerById(Long id) {
        return carDealerMapper.selectDealerById(id);
    }

    @Override
    public CarDealer getDealerByUserId(Long userId) {
        return carDealerMapper.selectDealerByUserId(userId);
    }

    @Override
    public List<CarDealer> searchDealers(Map<String, Object> params) {
        return carDealerMapper.searchDealers(params);
    }

    @Override
    public int addDealer(CarDealer dealer) {
        return carDealerMapper.insertDealer(dealer);
    }

    @Override
    public int updateDealer(CarDealer dealer) {
        return carDealerMapper.updateDealer(dealer);
    }

    @Override
    public int deleteDealer(Long id) {
        return carDealerMapper.deleteDealer(id);
    }

    @Override
    public int deleteDealerByUserId(Long userId) {
        return carDealerMapper.deleteDealerByUserId(userId);
    }

    @Override
    public Map<String, Object> getDealersByPage(int pageNum, int pageSize) {
        Map<String, Object> result = new HashMap<>();
        int offset = (pageNum - 1) * pageSize;
        List<CarDealer> dealers = carDealerMapper.selectDealersByPage(offset, pageSize);
        int total = carDealerMapper.selectDealerCount();
        result.put("data", dealers);
        result.put("total", total);
        return result;
    }
} 